/**
 * Created by levy on 16/6/15.
 */
/**
 * textarea  可以有默认值
 * 参数:
     addClass:
     name:
     value: 默认值
     placeholder:
     readonly:
 
    //组件交互函数,详见report.js
    blurFn
    focusFn
 */
var TextArea = React.createClass({
    getDefaultProps(){
        return {
            focusFn: () => console.log('textarea focus'),
            blurFn: () => console.log('textarea blur'),
        }
    },
    getInitialState() {
        return {
            value: this.props.value,
            hasReceived: false,
        }
    },
    render() {
        let props = this.props,
            value = this.state.value,
            focusFn = props.focusFn,
            blurFn = props.blurFn;
        return (
            <textarea className={(props.addClass || '') + ' lf-textarea' }
                   name={props.name} id={props.name} value={value} placeholder={props.placeholder}
                   onChange={this._onChange} readOnly={this.props.readonly}
                   onFocus={focusFn} onBlur={blurFn}/>
        )
    },
    componentWillReceiveProps(nextProps) {
        if(!nextProps.value || this.state.hasReceived)  return;

        this.setState({value: nextProps.value, hasReceived: true});
    },
    _onChange(e) {
        this.setState({value: e.target.value});
    }
});

export default TextArea;
